//https://www.nowcoder.com/practice/762836f4d43d43ca9deb273b3de8e1f4?tpId=13&tqId=23252&ru=/exam/oj/ta&qru=/ta/coding-interviews/question-ranking&sourceUrl=%2Fexam%2Foj%2Fta%3Fpage%3D1%26tpId%3D13%26type%3D13
//思想：1.sort排序；2.算出0的个数；3.找出非零数值中的差距；4.差距与0的个数做比较；

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

class Solution {
  public:
    bool IsContinuous(vector<int> numbers) {

        //判断有几个大小王
        if (numbers.empty()) return false;
        int zero_num = 0;

        std::sort(numbers.begin(), numbers.end());
        int differ_num = 0;

        for (int i = 0; i < numbers.size(); ++i) {
            if (numbers[i] == 0) {
                ++zero_num;
                continue;
            }
            if ((i + 1) < numbers.size() && numbers[i] == numbers[i + 1]) {
                return false;
            } else if ((i + 1) < numbers.size()) {
                differ_num += numbers[i + 1] - numbers[i] - 1;
            }
        }

        return differ_num  <= zero_num  ? true : false;
    }
};